<%--
   insecptCi
   Copyright (c) 2015 ISPERP
   Version : 1.0.0
 --%>
<%@tag import="org.apache.commons.lang3.StringUtils"%>
<%@tag import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@tag import="itsm.isperp.control.form.table.inspect.InspectTreeTable"%>
<%@tag import="itsm.isperp.framework.utils.TreeNodeUtils"%>
<%@tag
	import="itsm.isperp.module.repository.task.TskInspectTemplateMapper"%>

<%@tag import="java.util.Map"%>
<%@tag import="java.util.List"%>
<%@ tag language="java" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<%@ attribute name="defId" required="true" type="java.lang.String"
	description="defId"%>

<%@ attribute name="taskId" required="false" type="java.lang.String"
	description="taskId"%>
<%@ attribute name="readonly" required="false" type="java.lang.Boolean"
	description="readonly"%>



<%
	TskInspectTemplateMapper tskInspectTemplateMapper = ContextHolder
	.getSpringBean("tskInspectTemplateMapper");
	List<Map<String, Object>> costs = tskInspectTemplateMapper
	.getCost(defId);

	costs = TreeNodeUtils.sortTree(costs);

	InspectTreeTable tt = null;
	if (StringUtils.isEmpty(taskId)) {
		tt = new InspectTreeTable(defId);
	} else {
		boolean ireadonly = false;
		if (readonly != null && readonly == true) {
	ireadonly = true;
		}
		tt = new InspectTreeTable(defId, taskId, ireadonly);
	}

	for (Map<String, Object> m : costs) {
		long count_id = Long.valueOf(m.get("count_id").toString());
		if (count_id == 1) {
	String id = (String) m.get("id");
	String treenodeName = (String) m.get("treenode_name_path");
	String code = (String) m.get("code");
	String ci_id = (String) m.get("ci_id");
	String ci_name = (String) m.get("ci_name");
	String value = "";
	tt.addRow(id, treenodeName, ci_id, ci_name, code, value);
		}
	}
%>


<%=tt.renderHtml()%>



<script type="text/javascript">
<!--
	function openCiViewDialog(id) {
		isperp.openDialog({
			contentUrl : "configuration/ci/edit?id=" + id
		})
	}

	$("#template_table input[type='checkbox']").click(function() {

		var c = $(this).attr("class"), cid = this.id;
		$("." + c).each(function(index, item) {
			if (item.id != cid)
				item.checked = false;
			else {
				item.checked = true;
			}
		});

	});
//-->
</script>
